-- 2012-05-17 EM
alter procedure sp_get_phone_by_session
	@sid uniqueidentifier,
	@phone varchar(20) output
as
begin
	set nocount on;
	

	declare @pid bigint set @pid = null;
	declare @iid bigint set @iid = null;
	
	select @pid = phone_id, @iid = identificator_id from dbdata.dbo.user_sessions where id = @sid and dt_closed is null;
	if @pid is not null
		select @phone = phone from dbdata.dbo.phones where id = @pid;

end;
go

